import RPi.GPIO as GPIO
import time

readPin = 11
def callfun():
    if(GPIO.input()==0):
        print("low level,falling ")
    else:
        print("high level,rasing ")

def makerobo_setup():
    GPIO.setmode(GPIO.BOARD)  # 采用物理编号
    GPIO.setwarnings(False)  # 去除GPIO的警告
    # 软件上拉
    GPIO.setup(readPin, GPIO.IN,pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(readPin,GPIO.BOTH,callback=callfun,bounchtime=10)


def loop():
    makerobo_setup()
    while True:
        time.sleep(1)

def destroy():
    GPIO.cleanup()  #释放资源

if __name__=='__main__':
    try:
        loop()
    except KeyboardInterrupt:   #按下 ctrl+c 释放资源
        destroy()